@echo off
setlocal

echo 启动Nacos服务器...
start "Nacos Server" cmd /c "cargo run -p nacos-server"
timeout /t 5 /nobreak >nul

echo 测试健康检查...
curl -f http://localhost:8848/health || echo 健康检查失败

echo 测试服务注册...
curl -X POST "http://localhost:8848/nacos/v1/ns/instance?namespace=public^&serviceName=test-service^&ip=127.0.0.1^&port=8080^&weight=1.0^&healthy=true^&enabled=true^&ephemeral=true" ^
  -H "Content-Type: application/x-www-form-urlencoded" ^
  -d "" || echo 服务注册失败

echo 测试获取服务实例列表...
curl "http://localhost:8848/nacos/v1/ns/instance/list?namespace=public^&serviceName=test-service" || echo 获取服务实例列表失败

echo 测试服务注销...
curl -X DELETE "http://localhost:8848/nacos/v1/ns/instance?namespace=public^&serviceName=test-service^&ip=127.0.0.1^&port=8080" ^
  -H "Content-Type: application/x-www-form-urlencoded" ^
  -d "" || echo 服务注销失败

echo 测试配置发布...
curl -X POST "http://localhost:8848/nacos/v1/cs/configs" ^
  -H "Content-Type: application/json" ^
  -d "{\"namespace\":\"public\",\"group\":\"DEFAULT_GROUP\",\"dataId\":\"test-config\",\"content\":\"test-content\"}" || echo 配置发布失败

echo 测试获取配置...
curl "http://localhost:8848/nacos/v1/cs/configs?namespace=public^&group=DEFAULT_GROUP^&dataId=test-config" || echo 获取配置失败

echo 测试配置删除...
curl -X DELETE "http://localhost:8848/nacos/v1/cs/configs" ^
  -H "Content-Type: application/json" ^
  -d "{\"namespace\":\"public\",\"group\":\"DEFAULT_GROUP\",\"dataId\":\"test-config\"}" || echo 配置删除失败

echo 所有测试完成
echo 请手动停止Nacos服务器进程
